<template>
  <view class="container">
    <view class="result">
      <view class="title">
        目前您累计折算保费为 <text class="title-total"> {{ total }}</text>
      </view>
      <view class="title" v-if="starLevel">
        现达到新华瑞 <text class="title-total">{{ starLevel }}</text> 星
      </view>
      <view class="title" v-show="starLevel < 5">
        距 <text class="title-total">{{ starLevel + 1 }}</text> 星差额
        <text class="title-total">{{ diff }}</text>
      </view>
    </view>
    <view class="resut-star">
      <view class="star-item">
        <view class="img-box img-box1">
          <image class="img1" src="@/static/1.png"></image>
          <text class="img-star">5星</text>
        </view>
        <text class="text">30万以上</text>
      </view>
      <view class="star-item">
        <view class="img-box img-box2">
          <image class="img2" src="@/static/2.png"></image>
          <text class="img-star">4星</text>
        </view>
        <text class="text">20-30万以上</text>
      </view>
      <view class="star-item">
        <view class="img-box img-box3">
          <image class="img3" src="@/static/3.png"></image>
          <text class="img-star">3星</text>
        </view>
        <text class="text">10-20万以上</text>
      </view>
      <view class="star-item">
        <view class="img-box img-box4">
          <image class="img4" src="@/static/4.png"></image>
          <text class="img-star">2星</text>
        </view>
        <text class="text">5-10万以上</text>
      </view>
      <view class="star-item">
        <view class="img-box img-box5">
          <image class="img5" src="@/static/5.png"></image>
          <text class="img-star">1星</text>
        </view>
        <text class="text">1-5万以上</text>
      </view>
    </view>
    <view class="btn-box">
      <button class="btn" @click="reClacClick">
        <img class="icon" src="/static/calc.png" alt="" />
        <text>重新测算</text>
      </button>
    </view>
  </view>
</template>

<script setup>
import { onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";
const reClacClick = () => {
  uni.navigateBack({
    delta: 1,
  });
};
let total = ref("");
let starLevel = ref("");
let diff = ref("");
onLoad((parmas) => {
  total.value = parmas.total;
  if (total.value < 10000) {
    diff = Math.abs(total.value - 10000); // 不到1星
  } else if (total.value >= 10000 && total.value < 50000) {
    diff = Math.abs(total.value - 50000); // 1星
    starLevel = 1; // 1星
  } else if (total.value >= 50000 && total.value < 100000) {
    diff = Math.abs(total.value - 100000);
    starLevel = 2; // 2星
  } else if (total.value >= 100000 && total.value < 200000) {
    diff = Math.abs(total.value - 200000);
    starLevel = 3; // 3星
  } else if (total.value >= 200000 && total.value < 300000) {
    diff = Math.abs(total.value - 300000); // 不到1星
    starLevel = 4; // 4星
  } else if (total.value >= 300000) {
    starLevel = 5; // 5星
  }
});
</script>

<style lang="scss" scoped>
.container {
  background: #f8f8f8;
  box-sizing: border-box;
  padding: 0 30rpx;
  height: 100%;
  padding-top: 20rpx;


  .title {
    font-family: PingFangSC-Medium;
    font-size: 30rpx;
    color: #333333;
    letter-spacing: -0px;
    text-align: center;
    font-weight: 500;
    line-height: 60rpx;

    .title-total {
      font-size: 46rpx;
      color: #FF5744
    }
  }

  .resut-star {
    margin-top: 20rpx;

    .star-item {
      display: flex;
      align-items: center;
      margin-bottom: 20rpx;

      .img-box {
        position: relative;
        height: 100rpx;

        .img-star {
          position: absolute;
          font-size: 16rpx;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          font-family: PingFangSC-Regular;
          font-size: 24rpx;
          color: #ffffff;
          letter-spacing: 0;
          font-weight: 400;
        }
      }

      .img-box1 {
        margin-left: 26%;

        .img-star {
          top: 62%;
        }
      }

      .img-box2 {
        margin-left: 20%;

        .img-star {
          top: 45%;
        }
      }

      .img-box3 {
        margin-left: 15%;

        .img-star {
          top: 48%;
        }
      }

      .img-box4 {
        margin-left: 11%;

        .img-star {
          top: 45%;
        }
      }

      .img-box5 {
        margin-left: 5%;

        .img-star {
          top: 45%;
        }
      }

      .img1 {
        width: 180rpx;
        height: 100%;
      }

      .img2 {
        width: 260rpx;
        height: 100%;
      }

      .img3 {
        width: 340rpx;
        height: 100%;
      }

      .img4 {
        width: 400rpx;
        height: 100%;
      }

      .img5 {
        width: 490rpx;
        height: 100%;
      }

      .text {
        font-family: PingFangSC-Medium;
        font-size: 28rpx;
        color: #fff;
        letter-spacing: -0px;
        font-weight: 500;
        background: #f4cd29;
        border-radius: 20rpx;
        box-sizing: border-box;
        padding: 6rpx 10rpx;
      }
    }
  }

  .btn-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 60rpx;

    .icon {
      width: 40rpx;
      height: 40rpx;
      margin-right: 10rpx;
    }

    .btn {
      background: #ffffff;
      border: 1rpx solid rgb(0, 128, 255);
      /* height: 96rpx; */
      font-family: PingFangSC-Regular;
      font-size: 32rpx;
      color: #414141;
      letter-spacing: 0;
      text-align: center;
      font-weight: 400;
      margin: 0;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #016fff;
    }
  }
}
</style>
